<?php
namespace app\components;

use app\models\Options;

class Formatter extends \yii\i18n\Formatter{

    const Enable = '✅';
    // const Disable = '❌'; 
    // const Enable = '<i class="fas fa-check-square fa-lg" style="color: #0cad01;"></i>';
    const Disable = '<i class="fas fa-times" style="color: #f52929;"></i>';

    public function asAvailable($value){
        if ($value === true){
            return self::Enable;
        }else if ($value > 0){
            return $value;
        }else{
            return self::Disable;
        }
    }

    public function asSwitch($value){
        if (empty($value)){
            return '❌ 关';
        }else{
            return self::Enable . ' 开';
        }
    }

    public function asMonthly($value){
        if ($value === false){
            return self::Disable;
        }else if ($value < 0){
            return abs($value);
        }else{
            return $value . '/月';
        }        
    }

    /** 结尾的 n 代表 number */
    public function asMonthlyn($value){
        if ($value === false){
            return self::Disable;
        }else if ($value < 0){
            return abs($value) . '个';
        }else{
            return $value . '/月';
        }
    }

    /** 数量：个 */
    public function asNumber($value){
        return $value . ' 个';
    }

    /** 规则相关 */

    public function asMinute($value){
        return $value . ' 分钟';
    }

    public function asSecond($value){
        return $value . ' 秒';
    }
    
    public function asPoint($value){
        return $value . ' 分';
    }

    public function asTimes($value){
        return $value . ' 次';
    }

    public function asPeriod($value){
        return $value . ' 节';
    }

    public function asPerson($value){
        return $value . ' 人';
    }

    public function asProjectState($value){
        $states = Options::projectStates();
        return $states[$value] ?? '未定义';
    }

    public function asContactSource($value){
        $sources = Options::contactSources();
        return $sources[$value] ?? '未定义';
    }

    public function asIssuePriority($value){
        $priorities = Options::issuePriorities();
        return $priorities[$value] ?? '未定义';
    }

    public function asIssueState($value){
        $options = Options::issueStates();
        return $options[$value] ?? '未定义';
    }
}

?>